<div id="news">
<div>
    <div>
        Published: <input type="text" id="news_published" name="published" class="text" value="" />
        Expired: <input type="text" id="news_expired" name="expired" class="text" value="" />
    </div>
    <div>
        <textarea id="news_content" onchange="content_changed();"><?php $this->write('content');?></textarea>
    </div>
</div>
</div>
<script type="text/javascript">
var calendar, news_published, news_expired;
z.addEvent(window, 'load', function () {
    <?php if ('add' == tos_http_get('a')) : ?>
    knm.add_require('content');
    <?php endif; ?>
    calendar = new z.Calendar();
    news_published = z.s('news_published');
    news_expired = z.s('news_expired');
    news_published.onclick = function (e) {
        set_datetime(this);
    };
    news_published.onmouseout = function (e) {
        hide_datetime(e);
    };
    
    news_expired.onclick = function (e) {
        set_datetime(this);
    };

    news_expired.onmouseout = function (e) {
        hide_datetime(e);
    };
    <?php if ($this->has_data('published')):?>
    news_published.value = z.parseTime(new Date(<?php $this->write('published');?> * 1000));
    <?php endif;?>
    <?php if ($this->has_data('expired')):?>
    news_expired.value = z.parseTime(new Date(<?php $this->write('expired');?> * 1000));
    <?php endif;?>
});
function content_changed() {
    knm.set('content', z.s('news_content').value);
}
function set_datetime(target) {
    var offset = z.getAbsOffset(target);
    calendar.setPos(offset.left + 5, offset.top + 20);
    calendar.show(target.value);
    calendar.submit = function () {
        target.value = z.parseTime(this.selectedDay);
        knm.set(target.name, Math.ceil(this.selectedDay.getTime() / 1000));
        this.hide();
    }
}
function hide_datetime(e) {
    calendar.autoHide(e);
}
var rt = new z.richtext({
    'elem': 'news_content'
});


/*
z.addEvent(document.body, 'load', function () {
    knm.add_require('template');
});

function template_changed(target) {
    knm.set('template', target.value);
}
)*/
</script>